package com.inspur.edp.formserver.viewmodel.extendinfo.entity;

import com.inspur.edp.cdp.common.utils.json.JsonUtil;
import io.swagger.util.Json;
import javax.persistence.AttributeConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VoConfigCollectionInfoConverter implements AttributeConverter<VoConfigCollectionInfo, String> {
    private static Logger logger = LoggerFactory.getLogger(VoConfigCollectionInfo.class);

    @Override
    public String convertToDatabaseColumn(VoConfigCollectionInfo attribute) {
        return Json.pretty(attribute);
       // return JsonSerializerUtils.writeValueAsString(attribute);
    }

    @Override
    public VoConfigCollectionInfo convertToEntityAttribute(String dbData) {
        if (dbData == null || dbData.isEmpty()) {
            return new VoConfigCollectionInfo();
        }
        VoConfigCollectionInfo configCollectionInfo = null;
        try {
            configCollectionInfo = JsonUtil.toObject(dbData, VoConfigCollectionInfo.class);
        } catch (Exception e) {
            throw new RuntimeException("反序列化出错："+ dbData, e);
        }
        return configCollectionInfo;
    }
}
